home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_353 / aztecarp / fmalloc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  83 lines

  1. /* fmalloc.c */
  2.  
  3. /* !!! could add a magic # to this to make free() more robust */
  4. struct mem {
  5.     struct DefaultTracker *tracker;
  6. };
  7.  
  8.  
  9. /*doc fmalloc
  10. NAME
  11.     fmalloc -- arp'd fmalloc()
  12.  
  13. SYNOPSIS
  14.     result = fmalloc(size,flags)
  15.  
  16.     void *result;
  17.     unsigned long size,flags;
  18.  
  19. FUNCTION
  20.     Allocates memory using Amiga memory flags (defined in
  21.     <exec/memory.h>).  Memory allocated this way can later be freed by
  22.     calling free().  These allocations use Arp resource tracking an
  23.     therefore will be freed by ArpExit().
  24.  
  25. INPUTS
  26.     size - number of bytes to allocate
  27.     flags - memory (MEMF_) flags
  28.  
  29. RESULTS
  30.     result - pointer to memory block or NULL on failure
  31.  
  32. SEE ALSO
  33.     malloc(), free(), fmalloc()
  34.  
  35. MODULE
  36.     fmalloc.c
  37. *end */
  38.  
  39. void *fmalloc(size,flags)
  40. unsigned long size,flags;
  41. {
  42.     register struct mem *mp;
  43.  
  44.     if (!(mp = ArpAllocMem(size+sizeof(struct mem), flags))) return NULL;
  45.  
  46.     mp->tracker = LastTracker;
  47.  
  48.     return (char *)mp + sizeof(struct mem);
  49. }
  50.  
  51. void *lmalloc(size)
  52. unsigned long size;
  53. {
  54.     return fmalloc (size,0L);
  55. }
  56.  
  57. void *calloc (nelem,size)
  58. unsigned nelem, size;
  59. {
  60.     return fmalloc ((unsigned long)nelem * size,MEMF_CLEAR);
  61. }
  62.  
  63. void *lcalloc (nelem,size)
  64. unsigned long nelem, size;
  65. {
  66.     return fmalloc (nelem * size,MEMF_CLEAR);
  67. }
  68.  
  69. void *malloc(size)
  70. unsigned size;
  71. {
  72.     return fmalloc ((unsigned long)size,0L);
  73. }
  74.  
  75. free(blk)
  76. char *blk;
  77. {
  78.     register struct mem *mp = (void *)(blk - sizeof(struct mem));
  79.  
  80.     FreeTrackedItem (mp->tracker);
  81.     return 0;
  82. }
  83.